VPATH += ./src
VPATH += $(INCLUDE)

# specify the compilier and build/link flags
CXX = g++
LDFLAGS = 
LIBS = -L/usr/lib -lmysqlpp -lmysqlclient
CXXFLAGS = -Wno-deprecated -O2
INCLUDE = -I/usr/include/mysql -I/usr/include/mysql++

# specify path and filenames
srcdir = ./src
bindir = ./bin
objdir = ./obj

basename = test dbclass decoder
obj = $(patsubst %, $(objdir)/%.o, $(basename))
goal = $(bindir)/test

# build rules
.PHONY: all clean realcelan info

all: info $(bindir) $(objdir) $(goal)
	@echo $(goal) complete
	
# print out some compilation information, like flags
info:
	@echo Build with CXXFALGS = $(CXXFLAGS)
	@echo and LDFLAGS = $(LDFLAGS)
	@echo and LIBS = $(LIBS)

# /clean/ deltes everything in the bindir and objdir	
clean:
	@rm -f $(obj) $(goal)

# /realclean/ essentially remove all the directories and the dependencies
realclean:
	@rm -rf $(objdir) $(bindir)
	
# build the directory in which .o files will go
$(objdir):
	@mkdir -p $@
	
# build the directory in which bin files will go
$(bindir):
	@mkdir -p $@
	
# build the executable
$(goal): $(obj)
	@echo $(CXX) $^ --> $@
	@$(CXX) $(LDFLAGS) $^ -o $@ $(LIBS)
	
# compilation rules
$(objdir)/test.o: test.cpp decoder.h
		@echo $(CXX) $< --> $@
		@$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDE)
		
$(objdir)/decoder.o: decoder.cpp decoder.h dbclass.h
		@echo $(CXX) $< --> $@
		@$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDE)
	
$(objdir)/dbclass.o: dbclass.cpp dbclass.h	
		@echo $(CXX) $< --> $@
		@$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDE)
	
	





